<?php
class TestController extends Controller
{
	public function indexAction()
	{
		$_SESSION['admin'] = UsersModel::model()->find(1);
		exit;
	}
	
	public function sAction()
	{
		// $_SESSION = array();
		echo '<pre>';
		print_r($_SESSION);
		exit;
	}
	
	public function tplAction()
	{
	}
	
	public function adduserAction()
	{
		for ($i=1; $i<101; $i++)
		{
			$email = $url = '';
			switch(mt_rand(0, 3))
			{
				case 0 : $email = '@sina.com';
					$url = 'http://www.sina.com';
					break;
				case 1 : $email = '@163.com';
					$url = 'http://www.163.com';
					break;
				case 2 : $email = '@126.com';
					$url = 'http://www.126.com';
					break;
				case 3 : $email = '@qq.com';
					$url = 'http://www.qq.com';
					break;
			}
			
			$sex = mt_rand(0, 2);
			$sex = $sex === 1 ? 'f' : ($sex === 0 ? 'm' : 'u');
			$user = array(
				'user_loginname' => CString::randStr(6) . '_' . $i,
				'user_password' => md5(CString::randStr(9)),
				//'group_id' => 0,
				'group_id' => mt_rand(1, 3),
				'user_nicename' => CString::randStr(6) . '_' . $i,
				'user_email' => CString::randStr(4) . '_' . $i . $email,
				'user_url' => $url,
				'display_name' => CString::randStr(4, 'LETTER'),
				'dt_registered' => date('Y-m-d H:i:s', mktime() - mt_rand(0, 3600*24*30*6)),
				'user_activation_key' => md5(CString::randStr(9)),
				'ip_last_login' => mt_rand(1, 255) . '.' . mt_rand(1, 255) . '.' . mt_rand(1, 255) . '.' . mt_rand(1, 255),
				'dt_last_login' => date('Y-m-d H:i:s', mktime() - mt_rand(0, 3600*24*30*6)),
				'user_status' => mt_rand(0, 1) === 0 ? 'n' : 'y',
				'user_sex' => $sex
			);
			
			$usersModel = new UsersModel();
			$usersModel->insert($user);
		}
		exit;
	}
	
	public function addModuleAction()
	{
		$moduleModel = V::M('modules');
		for ($i=0; $i<100; $i++)
		{
			$module = array(
				'module_name' => Helper::randStr(6) . '_' . $i,
				'module_tblprefix' => 'vo_' . Helper::randStr(6),
				'module_description' => Helper::randStr(8, 'LETTER'),
				'module_status' => mt_rand(0, 1) === 0 ? 'n' : 'y',
			);
			
			$moduleModel->insert($module);
		}
		exit;
	}
	
	public function addpostsAction()
	{
		$time = mktime();
		$s = 3600*24*30;
		for ($i=1; $i<1001; $i++)
		{
			$post_content = CString::randStr(60);
			$post = array(
				'post_title' => CString::randStr(6) . '_' . $i,
				'post_content' => $post_content,
				'category_id' => mt_rand(1, 12),
				'post_keywords' => substr($post_content, mt_rand(3, 10), mt_rand(5, 9)),
				'post_description' => substr($post_content, 0, mt_rand(15, 19)),
				'user_id' => 1,
				'menu_order' => 50,
				'access_count' => mt_rand(0, 9999),
				'dt_created' => date('Y-m-d H:i:s', $time - mt_rand($s*3, $s*6)),
				'dt_modify' => date('Y-m-d H:i:s', $time - mt_rand($s, $s*3)),
				'is_html' => mt_rand(0, 1) === 0 ? 'y' : 'n',
				'post_flags' => mt_rand(0, 1) === 0 ? array('h', 'c') : array('c', 'j'),
				'post_url' => '',
				'post_status' => mt_rand(0, 1) === 0 ? 'o' : (mt_rand(0, 1) === 0 ? 'c' : 't'),
				'allow_comment' => mt_rand(0, 1) === 0 ? 'y' : 'n'
			);
			
			$postsModel = new PostsModel();
			$postsModel->insert($post);
		}
		exit;
	}
	
	public function logAction()
	{
		//$log = new CLogStream(APP_DIR . '/data/logs1/system1.log');
		$log = new CLogDb('vo_logs');
		$log->err('用户名不正确');
		exit;
	}
	
}
